package com.example.mymvp3;

import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

import com.alibaba.android.arouter.launcher.ARouter;
import com.example.mymvp3.bean.SendBean;
import com.example.mymvp3.model.TaskModel;
import com.example.mymvp3.presenter.TaskPresenter;
import com.example.mymvp3.view.TaskBaseView;


public class MainActivity extends AppCompatActivity implements View.OnClickListener, TaskBaseView {

    private TextView tvShow;
    private Button btRequest,btStart;

    private TaskPresenter taskPresenter;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        tvShow = findViewById(R.id.tv_show);
        btRequest = findViewById(R.id.bt_request);
        btStart = findViewById(R.id.bt_start_second);

        btRequest.setOnClickListener(this);
        btStart.setOnClickListener(this);
        taskPresenter = new TaskPresenter();
        taskPresenter.setBaseView(this);
        taskPresenter.setBaseModel(new TaskModel());
    }

    @Override
    public void onClick(View v) {
        int viewId = v.getId();
        if (viewId == R.id.bt_request) {
            taskPresenter.callBackData();
        }else if (viewId == R.id.bt_start_second) {
//            ARouter.getInstance().build("/test/SecondActivity").navigation();
            //跨模块
            ARouter.getInstance().build("/mvp2/test/MainActivity").navigation();
//           startActivity(new Intent(MainActivity.this,SecondActivity.class));
        }
    }

    @Override
    public void onShowData(SendBean responseData) {
        tvShow.setText(responseData.toString());
    }

    @Override
    public void showLoading() {

    }

    @Override
    public void hideLoading() {

    }

    @Override
    protected void onPause() {
        super.onPause();
        if (taskPresenter.getBaseView() != null){
            taskPresenter.setBaseView(null);
        }
        if (taskPresenter.getBaseModel() != null){
            taskPresenter.setBaseModel(null);
        }
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();

    }
}
